/*
 * Copyright (c) 2008 niels
 *
 * This file is part of BlueRemote.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with BlueRemote; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 */

#import <Foundation/Foundation.h>

// Bluetooth Objective C Headers:
#import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h>
#import <IOBluetooth/objc/IOBluetoothRFCOMMChannel.h>

// Bluetooth C Headers:
#include <IOBluetooth/IOBluetoothUserLib.h>

@class IOBluetoothUserNotification;

@interface BlueRCServerInterface : NSObject {
    // This is the RFCOMM channel we connect to:
    IOBluetoothRFCOMMChannel		*mRFCOMMChannel;

    // Service Entry for the service we publish
    BluetoothRFCOMMChannelID		mServerChannelID;
    BluetoothSDPServiceRecordHandle	mServerHandle;
    
    IOBluetoothUserNotification		*mIncomingChannelNotification;
    
    // This is the method to call in the UI when new data shows up:
    SEL	mHandleNewDataSelector;
    id	mNewDataTarget;
    
    // This is the method to call when the RFCOMM channel disappears.
    SEL	mHandleRemoteDisconnectionSelector;
    id	mDisconnectionTarget;
    
    // This is the method to call when the RFCOMM channel disappears.
    SEL mHandleRemoteConnectionSelector;
    id	mConnectionTarget;
}

// Connection Method:
// returns TRUE if the connection was successful:
- (BOOL)publishService;

// Stops Providing chat services
// Removes the published services from the SDP dictionary:
// If a connection is in progress it will not interrupt it.
- (void)stopProvidingRCServices;

// Disconnection:
// closes the channel:
- (void)disconnectFromClient;

// New RFCOMM channel show up:
// A new RFCOMM channel shows up we have to make sure it is the one we are waiting for:
-(void) newRFCOMMChannelOpened:(IOBluetoothUserNotification *)inNotification channel:(IOBluetoothRFCOMMChannel *)newChannel;

// Returns the name of the device we are connected to
// returns nil if not connection:
- (NSString *)remoteDeviceName;

// Returns the name of the local bluetooth device
- (NSString *)localDeviceName;

// Send Data method
// returns TRUE if all the data was sent:
- (BOOL)sendData:(void *)buffer length:(UInt32)length;

// IOBluetoothRFCOMMChannel delegate methods
- (void)rfcommChannelData:(IOBluetoothRFCOMMChannel*)rfcommChannel data:(void *)dataPointer length:(size_t)dataLength;
- (void)rfcommChannelClosed:(IOBluetoothRFCOMMChannel*)rfcommChannel;

// Registers selector for incoming data:
// tells to this class to call myTarget and myTargetAction when new data shows up:
- (void)registerForNewData:(id)myTarget action:(SEL)actionMethod;

// Registers selector for disconnection:
// tells to this class to call myTarget and myTargetAction when the channel disconnects:
- (void)registerForTermination:(id)myTarget action:(SEL)actionMethod;

// Registers selector for a successful completed connection:
// tells to this class to call myTarget and myTargetAction when the channel disconnects:
- (void)registerForNewConnection:(id)myTarget action:(SEL)actionMethod;


@end
